<?php

namespace app\mall\controller;

use app\data\controller\api\Auth;
use app\mall\logic\indexLogic;
use app\mall\logic\orderLogic;

class Order extends Auth
{

    //提交预览订单
    public function preview_order()
    {
        $is_shopping_cart = request()->param('is_shopping_cart', 0);
        $goods_info       = request()->param('goods_info', '');
        $logic            = new orderLogic();
        $res              = $logic->preview_order($this->uuid, $is_shopping_cart, $goods_info);
        if ($res['code'] == 200) {
            $this->success('提交预览订单', $res['data']);
        }
        $this->error($res['msg'], '', $res['code']);
    }

    //提交支付-余额
    public function submit_payment()
    {
        $goods_info = request()->param('goods_info', '');
        $coupon_id = request()->param('coupon_id', 0);
        $address_id = request()->param('address_id', 0);
        $pay_password = request()->param('pay_password', '');

        $logic = new orderLogic();
        $res = $logic->submit_payment($goods_info, $this->uuid, $coupon_id, $address_id, $pay_password);
        if ($res['code'] == 200) $this->success($res['msg']);
        $this->error($res['msg'], '', $res['code']);
    }

    //提交支付-微信支付宝
    public function submit_payment2()
    {
        $goods_info = request()->param('goods_info', '');
        $coupon_id = request()->param('coupon_id', 0);
        $address_id = request()->param('address_id', 0);
        $pey_type = request()->param('pey_type', '');

        $logic = new orderLogic();
        $res = $logic->submit_payment2($goods_info, $this->uuid, $coupon_id, $address_id, $pey_type);
//        var_dump($res);
//        die;
//        $this->success('发起支付',$res['pay']);
        if ($res['code'] == 200) $this->success($res['msg'], $res['pay']);
        $this->error($res['msg'], '', $res['code']);
    }


    /**
     * 预购预览
     * @return void
     */
    public function preview_booking()
    {
        $id      = $this->request->param('id', 0);
        $seq_num = $this->request->param('seq_num', 0);
        $buy_num = $this->request->param('buy_num', 0);

        $response = (new orderLogic())->preview_booking($id, $seq_num, $buy_num);
        $this->success('预定预览', $response);
    }

    /**
     * 预购下单
     * @return void
     */
    public function draw_booking()
    {
        $goods_info = request()->param('goods_info', '');
        $coupon_id = request()->param('coupon_id', 0);
        $address_id = request()->param('address_id', 0);
        $pay_password = request()->param('pay_password', '');

        $logic = new orderLogic();
        $res = $logic->submit_payment($goods_info, $this->uuid, $coupon_id, $address_id, $pay_password);
        if ($res['code'] == 200) {
            $this->success($res['msg']);
        }

        $this->error($res['msg'], '', $res['code']);
    }


    public function booking_list() {
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);

        $logic = new indexLogic();
        $items = $logic->booking_list($this->uuid, $page, $limit);
        $this->success('预购记录', $items);
    }


    //晒单
    public function comment()
    {
        $record_id = request()->param('record_id', 0);
        $comment = request()->param('comment', '');
        $images = request()->param('images', '');

        $logic = new orderLogic();
        $res = $logic->comment($this->uuid, $record_id, $comment, $images);
        if ($res['code'] == 200) $this->success($res['msg']);
        $this->error($res['msg'], '', $res['code']);
    }

    //最新开奖
    public function new_record_list()
    {
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);
        $logic = new orderLogic();
        $data = $logic->new_record_list($page, $limit);
        $this->success('最新开奖', $data);
    }

    //乐购记录
    public function record_list()
    {
        $is_win = request()->param('is_win', 0);
        $state = $this->request->param('state', -1);
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);
        $logic = new orderLogic();
        $data = $logic->record_list($this->uuid, $state, $is_win, $page, $limit);
        $this->success('购买记录', $data);
    }

    //晒单记录
    public function comment_list()
    {
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);
        $logic = new orderLogic();
        $data = $logic->comment_list($this->uuid, $page, $limit);
        $this->success('晒单记录', $data);
    }

    //充值余额-微信支付宝
    public function recharge()
    {
        $recharge_money = request()->param('recharge_money', 0);
        $pay_type = request()->param('pay_type', '');

        $logic = new orderLogic();
        $res = $logic->recharge($this->uuid, $recharge_money, $pay_type);

        if ($res['code'] == 200) $this->success($res['pay']);
        $this->error($res['msg'], '', $res['code']);

    }


}